//
//  ByMyOrderSearchVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/25.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByMyOrderSearchVC.h"

// view
#import "ByViewCitySearch.h"            // 搜索栏
#import "ByViewMyOrderSearchHeader.h"   // hedaer-历史记录和删除

@interface ByMyOrderSearchVC () <UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collect;

@end

@implementation ByMyOrderSearchVC
#pragma mark - view mehtod
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"订单搜索";
    self.view.backgroundColor = BY_BG_COLOR;
    
    [self addLeftBackBarButtonItem];
    
    [self createViews];
    
}

#pragma mark - 创建视图
- (void)createViews {
    
    // 城市搜索
    ByViewCitySearch *searchView = [ByViewCitySearch new];
    [self.view addSubview:searchView];
    searchView.searchBlock = ^(NSString *text) {
        [self search:text];
    };
    [searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(@0);
        make.height.equalTo(@60);
    }];

    // 列表
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 10;
    layout.itemSize = CGSizeMake((self.view.width - 10 * 5) / 4, 35);
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    
    self.collect = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collect.backgroundColor = BY_BG_COLOR;
    self.collect.delegate = self;
    self.collect.dataSource = self;
    [self.view addSubview:self.collect];
    [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(searchView.mas_bottom);
        if (@available(ios 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(@0);
        }
    }];
    
    [self.collect registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.collect registerClass:[ByViewMyOrderSearchHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
}

#pragma mark - UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = BY_RED_COLOR;
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(SCREEN_WIDTH, 50);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    ByViewMyOrderSearchHeader *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
    
    return header;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:false];

}



#pragma mark - 点击事件
- (void)search:(NSString *)text {
    
    if (text.length == 0) {
    } else {
        
    }
    [_collect reloadData];
    
}



@end
